package com.wing.platform.order.model.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableName;
import com.baomidou.mybatisplus.core.enums.IEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.wing.mybatis.common.BaseEntity;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import org.apache.commons.lang.StringUtils;
import org.springframework.format.annotation.DateTimeFormat;

import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 销售订单表
 *
 * @author
 */
@Data
@NoArgsConstructor
@Accessors(chain = true)
@TableName("sel_order")
public class Order extends BaseEntity<Order> implements Serializable {

    private static final long serialVersionUID = 1L;

    public enum Status implements IEnum<Integer> {

        /**
         * 待审核
         */
        pending(0,"待审核"),

        /**
         * 待受理
         */
        pass(1,"待受理"),
        /**
         * 已受理
         */
        accept(2,"已受理"),
        /**
         * 确认收货
         */
        affirm(3,"确认收货");

        private int code;
        private String desc;

        Status(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
    }

    public enum DistributionStatus implements IEnum<Integer> {

        /**
         * 待受理备货
         */
        stayConfirm(0,"待受理备货"),
        /**
         * 受理备货中
         */
        confirming(1,"受理备货中"),
        /**
         * 受理备货完成
         */
        complete(2,"受理备货完成");

        private int code;
        private String desc;

        DistributionStatus(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
    }

    /*public enum LeaseLength implements IEnum<Integer> {

        *//**
         * 1年
         *//*
        one(1,"1年"),
        *//**
         * 2年
         *//*
        two(2,"2年"),
        *//**
         * 3年
         *//*
        three(3,"3年");

        private int code;
        private String desc;

        LeaseLength(int code,String desc){
            this.code=code;
            this.desc=desc;
        }


        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
        @JsonCreator
        public static LeaseLength jsonCreator(String name) {
            if (StringUtils.isNotBlank(name)) {
                for (LeaseLength item : values()) {
                    if (item.name().equals(name.trim())) {
                        return item;
                    }
                }
            }
            return null;
        }
    }*/

    public enum Type implements IEnum<Integer> {

        /**
         * 智能柜
         */
        cabinet(0,"智能柜"),
        /**
         * 其他
         */
        other(1,"其他");

        private int code;
        private String desc;

        Type(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
    }

    public enum Mode implements IEnum<Integer> {

        /**
         * 销售
         */
        sell(0,"销售"),
        /**
         * 铺货
         */
        dist(1,"铺货"),
        /**
         * 出租
         */
        lease(2,"出租"),
        /**
         * 赠送
         */
        give(3,"赠送");

        private int code;
        private String desc;

        Mode(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
    }

    public enum WarehouseSource implements IEnum<Integer> {

        /**
         * 进销存
         */
        stock(0,"进销存"),
        /**
         * 云端云仓
         */
        cloud(1,"云端云仓"),
        /**
         * 智能柜
         */
        smartCabinet(2,"智能柜");

        private int code;
        private String desc;

        WarehouseSource(int code,String desc){
            this.code=code;
            this.desc=desc;
        }

        @Override
        public Integer getValue(){
            return this.code;
        }

        public String getDesc(){
            return this.desc;
        }
        @JsonCreator
        public static WarehouseSource jsonCreator(String name) {
            if (StringUtils.isNotBlank(name)) {
                for (WarehouseSource item : values()) {
                    if (item.name().equals(name.trim())) {
                        return item;
                    }
                }
            }
            return null;
        }
    }

    /**
     * 创建者
     */
    private Long creator;

    /**
     * 修改者
     */
    private Long modifier;

    /**
     * 创建人
     */
    private String creatorName;

    /**
     * 修改人
     */
    private String modifierName;

    /**
     * 订单编号
     */
    private String code;

    /**
     * 订单编号用
     */
    private Integer day;

    /**
     * 订单编号用
     */
    private Integer no;

    /**
     * 客户编号(公司编号)
     */
    private String customerCode;

    /**
     * 客户联系人ID
     */
    private Long customerContactsId;

    /**
     * 订单状态
     */
    private Status status;

    /**
     * 订单状态描述
     */
    @TableField(exist = false)
    private String statusDesc;

    public String getStatusDesc() {
        return status == null ? null : status.getDesc();
    }

    /**
     * 受理备货状态
     */
    private DistributionStatus distributionStatus;

    /**
     * 受理备货状态描述
     */
    @TableField(exist = false)
    private String distributionStatusDesc;

    public String getDistributionStatusDesc() {
        return distributionStatus == null ? null : distributionStatus.getDesc();
    }

    /**
     * 所属合同ID
     */
    private Long contractId;

    /**
     * 开始时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime startTime;

    /**
     * 订单总金额
     */
    private BigDecimal amount;

    /**
     * 收货地址
     */
    private String address;

   /* *//**
     * 租赁时长
     *//*
    private LeaseLength leaseLength;

    *//**
     * 租赁时长描述
     *//*
    @TableField(exist = false)
    private String leaseLengthDesc;

    public String getLeaseLengthDesc() {
        return leaseLength == null ? null : leaseLength.getDesc();
    }*/

    /**
     * 业务员名称
     */
    private String operatorName;

    /**
     * 渠道编号
     */
    private String enterpriseCode;

    /**
     * 渠道名称
     */
    @TableField(exist = false)
    private String enterpriseName;

    /**
     * 订单类型
     */
    private Type type;

    /**
     * 订单类型描述
     */
    @TableField(exist = false)
    private String typeDesc;

    public String getTypeDesc() {
        return type == null ? null : type.getDesc();
    }

    /**
     * 销售方式
     */
    private Mode mode;

    /**
     * 销售方式描述
     */
    @TableField(exist = false)
    private String modeDesc;

    public String getModeDesc() {
        return mode == null ? null : mode.getDesc();
    }

    /**
     * 仓库源
     */
    private WarehouseSource warehouseSource;

    /**
     * 仓库源描述
     */
    @TableField(exist = false)
    private String warehouseSourceDesc;

    public String getWarehouseSourceDesc() {
        return warehouseSource == null ? null : warehouseSource.getDesc();
    }

    /**
     * 数量
     */
    private Integer quantity;

    /**
     *合作时长/租赁时长(月)
     */
    private Integer duration;

    /**
     * 到货时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime arrivalTime;

    /**
     * 截止时间
     */
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime deadline;

    /**
     * 客户联系人名称
     */
    private String contactsName;

    /**
     * 客户联系人电话
     */
    private String phone;

}
